/**
 * 自己封装api
 */
class Api {
	static promisic(func) {
	    return function (params = {}) {
	        return new Promise((resolve, reject) => {
	            const args = Object.assign(params, {
	                success: (res) => {
	                    resolve(res);
	                },
	                fail: (error) => {
	                    resolve(error);
	                }
	            });
	            func(args);
	        });
	    };
	}
	//数组去重
	static uniqueArr(arr){
	  var hash=[];
	  for (var i = 0; i < arr.length; i++) {
		 if(hash.indexOf(arr[i])==-1){
		  hash.push(arr[i]);
		 }
	  }
	  return hash;
	}
	//获取标签中的参数
	static getDataSet(event,key){
	    return event.currentTarget.dataset[key];
	}
	//获得输入框中字符长度
	static getLength(val) {  
		var str = new String(val);  
		var bytesCount = 0;  
		for (var i = 0 ,n = str.length; i < n; i++) {  
			var c = str.charCodeAt(i);  
			if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {  
				bytesCount += 1;  
			} else {  
				bytesCount += 1;  
			}  
		}  
		return bytesCount;  
	} 
	//判断是否为手机号
	static isPhoneNumber(tel) {
		var reg =/^1[3|4|5|6|7|8][0-9]{9}$/;
		return reg.test(tel);
	}
	//根据下标删除数组元素
	static DeleteArrIndex(arr,index){
		arr.splice(index,1);
		return arr;
	}
}
export default Api